#include "hovertoolbutton.h"
#include "utils/util.h"

#include <QHBoxLayout>
#include <QLabel>

HoverToolButton::HoverToolButton(QWidget *parent)
    : QToolButton(parent)
{
    //设置悬停事件支持
    setAttribute(Qt::WA_Hover, true); // 启用悬停事件支持
    setMouseTracking(true);
    setVerifyCodeButton();
}

void HoverToolButton::enterEvent(QEnterEvent *event)
{
    // qDebug() << "enterEvent";
    text_default_styleSheet = label->styleSheet();
    icon_default_styleSheet = label2->styleSheet();
    //#2F95D5
    label->setStyleSheet("QLabel{color:#2F95D5;}");
    setLabelIcon(":/resources/right-arrow2.png");
    QToolButton::enterEvent(event);
}

void HoverToolButton::leaveEvent(QEvent *event)
{
    label->setStyleSheet(text_default_styleSheet);
    setLabelIcon(":/resources/right-arrow.png");
    QToolButton::leaveEvent(event);
}

void HoverToolButton::setVerifyCodeButton()
{
    setMinimumSize(120, 30);
    setStyleSheet("QToolButton {border:none; }");

    QHBoxLayout *hLayoutIntoolBtn = new QHBoxLayout(this);
    hLayoutIntoolBtn->setAlignment(Qt::AlignCenter);
    label = new QLabel(this);
    setLable(label, "label", "使用验证码登录", "Microsoft YaHei", 10);
    label->setAlignment(Qt::AlignCenter);
    hLayoutIntoolBtn->addWidget(label);
    label2 = new QLabel(this);
    setLabelIcon(":/resources/right-arrow.png");
    // qDebug() << label->size();
    hLayoutIntoolBtn->addWidget(label2);
    hLayoutIntoolBtn->setContentsMargins(0, 0, 0, 0);
    hLayoutIntoolBtn->setSpacing(3);
}

void HoverToolButton::setLabelIcon(QString iconFilePath)
{
    QPixmap pixmap(iconFilePath);
    pixmap = pixmap.scaled(QSize(20, 13), Qt::KeepAspectRatio);
    label2->setPixmap(pixmap);
}
